package com.luobo.web;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.luobo.entity.Comment;
import com.luobo.entity.Guanka;
import com.luobo.entity.News;
import com.luobo.entity.Question;
import com.luobo.entity.Tujian;
import com.luobo.service.LuoboDao;

@Controller
@RequestMapping("luobo")
public class LuoboController {

	@Resource
	private LuoboDao luoboDao;
	
	/**
	 * 新闻的详细内容
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "news/{id}",method=RequestMethod.GET)
	public String detailOfNews(@PathVariable("id") Integer id,ModelMap map){
		News news = luoboDao.getNewsById(id);
		map.put("detail", news);
		return "detail";
	}
	@RequestMapping(value = "guanka/{id}/{type}",method=RequestMethod.GET)
	public String detailOfGonglve(@PathVariable("id") Integer id,@PathVariable("type") Integer type,ModelMap map){
		Guanka tujian = luoboDao.getGonglveById(id, type);
		map.put("detail", tujian);
		if(type == 2){
			return "video";
		}
		return "detail";
	}
	@RequestMapping(value = "tujian/{id}",method=RequestMethod.GET)
	public String detailOfTujian(@PathVariable("id") Integer id,ModelMap map){
		Tujian tujian = luoboDao.getTujianById(id);
		map.put("detail", tujian);
		return "detail";
	}
	@RequestMapping(value = "question/{id}",method=RequestMethod.GET)
	public String detailOfQuestion(@PathVariable("id") Integer id,ModelMap map){
		Question question = luoboDao.getQuestionById(id);
		map.put("detail", question);
		return "detail";
	}
	
	@RequestMapping(value = "comment",method=RequestMethod.POST)
	@ResponseBody
	public Integer  comment(@ModelAttribute Comment comment,ModelMap map){
		luoboDao.saveComment(comment);
		return 1;
	}
//	@RequestMapping(value = "show",method=RequestMethod.GET)
//	public String  show(ModelMap map){
//		return "show";
//	}
}
